package com.kelaite.procurement.repository;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.kelaite.procurement.entity.TPurchaseOrder;
import com.kelaite.procurement.entity.TPurchaseOrderItems;

public interface PurchaseOrderItemsRepository extends JpaRepository<TPurchaseOrderItems, Long>{
	
	public List<TPurchaseOrderItems> findByTPurchaseOrderOrderByOrderItemNoAsc(TPurchaseOrder tPurchaseOrder);
	
	@Query(value = "select count(*) from t_purchase_order_items where order_id =?1 and order_item_no =?2", nativeQuery = true)
	public int countByPurchaseOrderIdAndOrderItemNo(Long puchaseOrderId, int orderItemNo);
	
	@Modifying
	@Query(value = "update t_purchase_order_items o set o.quantityDelivered =:quantityDelivered, o.actualTime =:actualTime,o.gmtUpdateTime =:gmtUpdateTime, o.updatedBy =:updatedBy where o.id =:id")
	public int updatePurchaseOrderItems(@Param("id") Long id,
			@Param("quantityDelivered") Double quantityDelivered,
			@Param("actualTime") Date actualTime,
			@Param("gmtUpdateTime") Date gmtUpdateTime,
			@Param("updatedBy") String updatedBy);
}
